<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础数据列表')"/>
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <style type="text/css">
        .select-list li label:not(.radio-box) {
            width: 35%;
            text-align: right;
        }

        .select-list li {
            width: 30%;
            color: #333;
            display: block;
            float: left;
            margin-left: 0;
            margin-right: 0;
        }

        .select-list .select2-container--bootstrap {
            width: 55% !important;
            display: inline-block;
        }

        .bootstrap-table .fixed-table-container .table td, .bootstrap-table .fixed-table-container .table th {
            background-color: #ffffff;
        }

        table {
            table-layout: fixed;
        }

        .tableClass td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            background-color: #ffffff;
            width: 10%;
        }

        .tableClass td:nth-child(2):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .tableClass td:nth-child(3):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .tableClass td:nth-child(4):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .tableClass td:nth-child(5):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .tableClass td:nth-child(6):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .tableClass td:nth-child(7):hover {
            position: absolute;
            transform: translate(0%);
            box-shadow: 0 2px 9px #999;
            border-radius: 4px;
            color: #0e0e0e;
            z-index: 99999;
            width: 7%;
            height: auto;
            white-space: pre-wrap;
            word-break: break-all;
            word-wrap: break-word;
            opacity: 1;
            text-align: center;
        }

        .layer-ext-moon .layui-layer-btn .layui-layer-btn0 {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label class="font-noraml">测试件名称：</label>
                            <select class="form-control" id="deviceName" name="deviceName">
                                <option value="">请选择</option>
                                <option th:each="deviceName:${deviceNameList}" th:value="${deviceName}"
                                        th:text="${deviceName}"></option>
                            </select>
                        </li>
                        <li>
                            <label class="font-noraml">测试件件号：</label>
                            <select class="form-control" id="devicePn" name="devicePn">
                                <option value="">请选择</option>
                                <option th:each="devicePn:${devicePnList}" th:value="${devicePn}"
                                        th:text="${devicePn}"></option>
                            </select>
                        </li>
                        <li>
                            <label class="font-noraml">序列号：</label>
                            <select class="form-control" id="deviceSn" name="deviceSn">
                                <option value="">请选择</option>
                                <option th:each="deviceSn:${deviceSnList}" th:value="${deviceSn}"
                                        th:text="${deviceSn}"></option>
                            </select>
                        </li>
                        <!--
                        <li>
                            <label class="font-noraml">测试子项编号：</label>
                            <select class="form-control" id="testSubItemNo" name="testSubItemNo">
                                <option value="">请选择</option>
                                <option th:each="testSubItemNo:${testSubItemNoList}" th:value="${testSubItemNo}"
                                        th:text="${testSubItemNo}"></option>
                            </select>
                        </li>
                        -->
                        <li>
                            <label>是否通过：</label>
                            <input style="width: 25%" type="text" id="testSubItemIsPass" name="testSubItemIsPass"/>
                        </li>
                        <li style="width: 40%; margin-left: -1.5%">
                            <label style="width: 30%;">测试时间：</label>
                            <input style="width: 70%;" type="text" id="startTime" name="params[beginTime]" placeholder="开始时间 - 结束时间">
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
<!--            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:componentinfo:add">-->
<!--                <i class="fa fa-plus"></i> 添加-->
<!--            </a>-->
<!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
<!--               shiro:hasPermission="system:componentinfo:edit">-->
<!--                <i class="fa fa-edit"></i> 修改-->
<!--            </a>-->
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
<!--               shiro:hasPermission="system:componentinfo:remove">-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="system:componentinfo:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table class="tableClass" id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:tbTest:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:tbTest:remove')}]];
    var prefix = ctx + "system/tbTest";

    $(function () {
        initDate();

        layui.use('laydate', function() {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#startTime',
                type: 'datetime',
                trigger: 'click',
                range: true
            });
        });

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            bmpDetailUrl: prefix + "/bmpDetail/{id}",
            modalName: "测试数据",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'testDate',
                    title: '测试时间'
                },
                {
                    field: 'deviceName',
                    title: '测试件名称'
                },
                {
                    field: 'devicePn',
                    title: '测试件件号'
                },
                {
                    field: 'deviceSn',
                    title: '序列号'
                },
                {
                    field: 'testItemContent',
                    title: '测试项'
                },
                {
                    field: 'testSubItemContent',
                    title: '测试子项'
                },
                {
                    field: 'testSubItemReqMax',
                    title: '最大值'
                },
                {
                    field: 'testSubItemReqMin',
                    title: '最小值'
                },
                {
                    field: 'testSubItemValue',
                    title: '测试值'
                },
                {
                    field: 'testSubItemUnit',
                    title: '单位'
                },
                {
                    field: 'testSubItemIsPass',
                    title: '是否通过'
                },
                {
                    field: 'testSubItemWavePath',
                    title: '波形文件路径(含名称)',
                    visible: false
                },
                {
                    title: '波形图',
                    align: 'center',
                    visible: false,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.testSubItemWavePath != undefined && row.testSubItemWavePath != null && row.testSubItemWavePath != '') {
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewWave(\'' + row.testSubItemWavePath + '\')"><i class="fa fa-edit"></i>查看</a>');
                        } else {
                            actions.push('<a style="background-color: #606060" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)"><i class="fa fa-edit"></i>查看</a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'testSubItemBmp',
                    title: '曲线分析图路径',
                    visible: false
                },
                {
                    title: '曲线图',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.testSubItemBmp != undefined && row.testSubItemBmp != null && row.testSubItemBmp != '') {
                            // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.testSubItemBmp + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showImg(\'' + row.testSubItemBmp + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        } else {
                            actions.push('<a style="background-color: #606060" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)"><i class="fa fa-edit"></i>查看</a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    title: '详情',
                    falign: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs  href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>详细</a>');
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.preview(\'' + row.testReportAddr + '\')"><i class="fa fa-edit"></i>浏览</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="downloadReport(\'' + row.testReportAddr + '\')"><i class="fa fa-download"></i>下载</a> ');
                        return actions.join('');
                    },
                    visible: false
                }]
        };
        $.table.init(options);
    });

    // 下载
    function downloadReport(testReportAddr) {
        window.location.href = ctx + "download/reportDownload?fileAddr=" + encodeURI(testReportAddr);
    }

    function initDate() {
        var date1 = new Date();
        date1.setTime(date1.getTime() - 7 * 24 * 60 * 60 * 1000);
        var month1 = date1.getMonth() + 1;
        var day1 = date1.getDate();
        if (date1.getMonth() < 9) {
            month1 = "0" + (date1.getMonth() + 1);
        }
        if (date1.getDate() < 10) {
            day1 = "0" + date1.getDate();
        }
        var startTime = date1.getFullYear() + "-" + month1 + "-" + day1 + " 00:00:00";

        var date2 = new Date();
        date2.setTime(date2.getTime());
        var month2 = date2.getMonth() + 1;
        var day2 = date2.getDate();
        if (date2.getMonth() < 9) {
            month2 = "0" + (date2.getMonth() + 1);
        }
        if (date2.getDate() < 10) {
            day2 = "0" + date2.getDate();
        }
        var endTime = date2.getFullYear() + "-" + month2 + "-" + day2 + " 00:00:00";

        // $("#startTime").val(startTime + " - " + endTime);
    }

    function reset() {
        $("#startTime").val("");
        $("#deviceName").select2("val", [""]);
        $("#devicePn").select2("val", [""]);
        $("#deviceSn").select2("val", [""]);
        $("#testSubItemNo").select2("val", [""]);
        $("#testSubItemIsPass").val("");
    }

    function viewWave (id) {
        table.set();
        open("查看波形文件", "system/tbTest/viewWave?fileName=" + encodeURI(id));
    }

    // 预览
    function preview (id) {
        table.set();

        open("预览", "preview?fileName=" + encodeURI(id));

    }

    function showImg(imgName){
        table.set();
        console.info("showImg"+imgName);
        open("预览", "system/tbTest/viewDiagram?fileName=" + encodeURI(imgName));
    }

    // 弹出层指定宽度
    function open (title, url, width, height, callback) {
        // 如果是移动端，就使用自适应大小弹窗
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(title)) {
            title = false;
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 800;
        }
        if ($.common.isEmpty(height)) {
            height = ($(window).height() - 50);
        }
        if ($.common.isEmpty(callback)) {
            callback = function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            }
        }
        top.layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: title,
            content: url,
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            btn: ['关闭'],
            yes: function (index, layero) {
                $.modal.close(index);
            }
        });
    }
</script>
</body>
</html>